package kr.hyunist.androidcomplete01saeildamil.ch17;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

public class MainActivityEx extends Activity {
	public static final int REQUEST_CODE_ANOTHER = 1001;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainactivityex);
		
		Button btn = (Button) findViewById(R.id.mainactivityexshowbtn);
		btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivityEx.this, AnotherActivity.class);
				startActivityForResult(intent, REQUEST_CODE_ANOTHER);
			}
			
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		
		if(requestCode == REQUEST_CODE_ANOTHER){
			Toast.makeText(MainActivityEx.this, "onActivityResult 메소드가 호출됨, 요청코드 : " + requestCode + ", 결과코드 : " + resultCode, Toast.LENGTH_LONG).show();
			
		}
		
		if(resultCode == RESULT_OK){
			String name = data.getExtras().getString("name");
			Toast.makeText(MainActivityEx.this, "응답으로 전달된 name : " + name, Toast.LENGTH_LONG).show();
			
		}
	}
	
	
}
